<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper"  v-if="operate">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="招标项目编号">
              {{ projectInfo.projectCode }} 
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="招标项目名称">
              {{ projectInfo.projectName }}
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="招标编号">
                <a-input placeholder="请输入招标编号" v-model="queryParam.tenderCode"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="公告标题">
                <a-input placeholder="请输入公告标题" v-model="queryParam.noticeName"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="状态">
                <j-dict-select-tag placeholder="请选择状态" v-model="queryParam.status" dictCode="sys_common_status" />
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a-button @click="handleAdd" type="primary" icon="plus" style="margin-left: 8px">新增</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :scroll="{ x: true }"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text, record">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            :preview="record.id"
            height="25px"
            alt=""
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>
        <span slot="action" slot-scope="text, record">
          <template v-if="record.status == 0 || record.status == 3">
            <a @click="handleEdit(record)">编辑</a>
            <a-divider type="vertical" />
            <a-popconfirm title="确定提交吗?" @confirm="() => handleSubmit(record)">
              <a>提交</a>
            </a-popconfirm>
          </template>
          <template v-else>
            <a @click="handleDetail(record)">详情</a>
            <!-- <a-divider type="vertical" />
            <a @click="handleChangeEdit(record)">变更</a> -->
          </template>
        </span>
      </a-table>

      <ex-tender-ann-qua-inquery-ann-modal ref="modalForm" @ok="modalFormOk" />
      <ex-tender-notice-change-modal ref="refChangeModal"   ></ex-tender-notice-change-modal>
    </div>
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import ExTenderAnnQuaInqueryAnnModal from './ExTenderAnnQuaInqueryAnnModal'
import ExTenderNoticeChangeModal from './ExTenderNoticeChangeModal'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import '@/assets/less/TableExpand.less'
import { httpAction, getAction } from '@/api/manage'

export default {
  name: 'NoticeList',
  mixins: [JeecgListMixin],
  components: {
    ExTenderAnnQuaInqueryAnnModal,
    ExTenderNoticeChangeModal
  },
  props: { projectId: {} ,bulletinType:{}, 
  operate: {
      type: Boolean,
      default: true,
    }
  },
  data() {
    return {
      description: '招标公告',
      title: '',
      width: 800,
      visible: false,
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '项目编号',
          align: 'center',
          dataIndex: 'tenderProjectCode',
        },
        {
          title: '标段编号',
          align: 'center',
          dataIndex: 'bidSectionCodes',
        },
        // {
        //   title: '监督部门代码',
        //   align: 'center',
        //   dataIndex: 'superviseDeptCode',
        // },
        // {
        //   title: '招标编号',
        //   align: 'center',
        //   dataIndex: 'tenderCode',
        // },
        {
          title: '标题',
          align: 'center',
          dataIndex: 'noticeName',
        },
        {
          title: '发布时间',
          align: 'center',
          dataIndex: 'noticeSendTime',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        {
          title: '截止时间',
          align: 'center',
          dataIndex: 'noticeEndTime',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'status_dictText',
        },
        {
          title: '创建时间',
          align: 'center',
          dataIndex: 'createTime',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/exTenderAnnQuaInqueryAnn/exTenderAnnQuaInqueryAnn/list',
        delete: '/exTenderAnnQuaInqueryAnn/exTenderAnnQuaInqueryAnn/delete',
        deleteBatch: '/exTenderAnnQuaInqueryAnn/exTenderAnnQuaInqueryAnn/deleteBatch',
        exportXlsUrl: '/exTenderAnnQuaInqueryAnn/exTenderAnnQuaInqueryAnn/exportXls',
        importExcelUrl: 'exTenderAnnQuaInqueryAnn/exTenderAnnQuaInqueryAnn/importExcel',
        submitAudit: 'exTenderAnnQuaInqueryAnn/exTenderAnnQuaInqueryAnn//submitAudit',
        queryProjectDetail: '/exProject/exProject/queryById',
      },
      dictOptions: {},
      superFieldList: [],
      projectInfo: {},
    }
  },
  watch: {
    projectId: {
      immediate: true,
      handler(val) {
        this.getProjectDetail()
      },
    },
  },
  created() {
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    getProjectDetail() {
      getAction(this.url.queryProjectDetail, { id: this.projectId }).then((res) => {
        if (res.success) {
          var record = res.result
          this.projectInfo = record
          this.loadData()
        }
      })
    },
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'tenderProjectCode', text: '招标项目编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bidSectionCodes', text: '相关标段（包）编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'unifiedDealCodes', text: '统一交易标识码', dictCode: '' })
      fieldList.push({ type: 'string', value: 'superviseDeptName', text: '监督部门名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'superviseDeptCode', text: '监督部门代码', dictCode: '' })
      fieldList.push({ type: 'string', value: 'tenderCode', text: '招标编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'noticeName', text: '公告标题', dictCode: '' })
      fieldList.push({ type: 'string', value: 'noticeContent', text: '公告内容', dictCode: '' })
      fieldList.push({ type: 'date', value: 'noticeSendTime', text: '公告发布时间' })
      fieldList.push({ type: 'string', value: 'noticeMedia', text: '公告发布媒体', dictCode: '' })
      fieldList.push({ type: 'string', value: 'url', text: '公告源url', dictCode: '' })
      fieldList.push({ type: 'string', value: 'noticeNature', text: '公告性质', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bulletinType', text: '公告类型', dictCode: '' })
      fieldList.push({ type: 'date', value: 'docGetStartTime', text: '招标文件/资格预审文件获取时间' })
      fieldList.push({ type: 'date', value: 'docGetEndTime', text: '招标文件/资格预审文件获取截止时间' })
      fieldList.push({
        type: 'string',
        value: 'tenderDocGetMethod',
        text: '招标文件/资格预审文件获取方法',
        dictCode: '',
      })
      fieldList.push({ type: 'date', value: 'bidDocReferEndTime', text: '投标文件/资格预审申请文件递交截止时间' })
      fieldList.push({ type: 'date', value: 'bidOpenTime', text: '开标时间' })
      fieldList.push({ type: 'BigDecimal', value: 'docPrice', text: '文件售价', dictCode: '' })
      fieldList.push({ type: 'string', value: 'docPriceCurrency', text: '文件售价币种', dictCode: '' })
      fieldList.push({ type: 'string', value: 'docPriceUnit', text: '文件售价单位', dictCode: '' })
      fieldList.push({
        type: 'string',
        value: 'bidDocReferMethod',
        text: '投标文件/资格预审申请文件递交方法',
        dictCode: '',
      })
      fieldList.push({ type: 'string', value: 'syndicatedFlag', text: '是否允许联合体投标', dictCode: '' })
      fieldList.push({ type: 'string', value: 'isPostpone', text: '是否延期开标', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bidOpenMethod', text: '开标方式/文件开启方式', dictCode: '' })
      fieldList.push({ type: 'string', value: 'qualType', text: '评审办法', dictCode: '' })
      fieldList.push({ type: 'string', value: 'tenderCodeType', text: '招标人代码类型', dictCode: '' })
      fieldList.push({ type: 'string', value: 'tendererCode', text: '招标人代码', dictCode: '' })
      fieldList.push({ type: 'string', value: 'tendererName', text: '招标人名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'tendererAddress', text: '招标人地址', dictCode: '' })
      fieldList.push({ type: 'string', value: 'tendererContactor', text: '招标人联系人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'tendererPhoneNumber', text: '招标人联系电话', dictCode: '' })
      fieldList.push({ type: 'string', value: 'tendererEmail', text: '招标人电子邮箱', dictCode: '' })
      fieldList.push({ type: 'string', value: 'tenderAgencyCodeType', text: '招标代理机构代码类型', dictCode: '' })
      fieldList.push({ type: 'string', value: 'tenderAgencyCode', text: '招标代理机构代码', dictCode: '' })
      fieldList.push({ type: 'string', value: 'tenderAgencyName', text: '招标代理机构名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'tenderAgencyAddress', text: '招标代理机构地址', dictCode: '' })
      fieldList.push({ type: 'string', value: 'tenderAgencyContactor', text: '招标代理机构联系人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'tenderAgencyPhoneNumber', text: '招标代理机构联系电话', dictCode: '' })
      fieldList.push({ type: 'string', value: 'tenderAgencyEmail', text: '招标代理机构电子邮箱', dictCode: '' })
      fieldList.push({ type: 'string', value: 'otherContent', text: '其他内容', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bulletinDuty', text: '公告发布责任人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bulletinDutyCodeType', text: '交易平台验证责任人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'attachmentCode', text: '附件关联标识号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'platformCode', text: '交易系统标识码', dictCode: '' })
      fieldList.push({ type: 'date', value: 'noticeEndTime', text: '公告截止时间' })
      fieldList.push({
        type: 'string',
        value: 'status',
        text: '状态',
        dictCode: 'sys_common_status',
      })
      fieldList.push({ type: 'date', value: 'createTime', text: '创建时间' })
      this.superFieldList = fieldList
    },
    handleCancel() {
      this.close()
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {},
    edit(record) {
      this.visible = true
      this.projectInfo = Object.assign({}, record)
      this.loadData()
    },
    handleChangeEdit(record){ 
      this.$refs.refChangeModal.edit(record)
      this.$refs.refChangeModal.title = '变更'
      this.$refs.refChangeModal.disableSubmit = false
    },
    handleAdd: function () {
      this.$refs.modalForm.add(this.projectInfo,this.bulletinType)
      this.$refs.modalForm.title = '新增'
      this.$refs.modalForm.disableSubmit = false
    },
    handleSubmit(row) {
      var that = this
      httpAction(this.url.submitAudit + '?id=' + row.id, row, 'post')
        .then((res) => {
          if (res.success) {
            that.$message.success(res.message)
            that.loadData()
          } else {
            that.$message.warning(res.message)
          }
        })
        .finally(() => {
          that.confirmLoading = false
        })
    },
    loadData(arg) {
      if (!this.url.list) {
        this.$message.error('请设置url.list属性!')
        return
      }
      console.log('this.projectInfo.projectId', this.projectInfo.projectId)
      if (!this.projectInfo.projectId) {
        return
      }
      if (!this.bulletinType) {
        return
      }
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }
      var params = this.getQueryParams() //查询条件
      params['projectId'] = this.projectInfo.projectId
      params['bulletinType'] = this.bulletinType
      this.loading = true
      getAction(this.url.list, params)
        .then((res) => {
          if (res.success) {
            //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            this.dataSource = res.result.records || res.result
            if (res.result.total) {
              this.ipagination.total = res.result.total
            } else {
              this.ipagination.total = 0
            }
            //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.loading = false
        })
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
